package com.my.study.net;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author: yidujun
 * @create: 2021/06/28 10:13
 */
@Slf4j(topic = "c.ServerTest")
public class ServerTest {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9999);
        log.debug("服务器开启.... {}", serverSocket.getClass());
        Socket socket = serverSocket.accept();
        InputStream inputStream = socket.getInputStream();
        byte[] buf = new byte[1024];
        int readLen = 0;
        while ((readLen = inputStream.read(buf)) != -1) {
            log.debug("消息：{}", new String(buf, 0, readLen));
        }

        //end 关闭流
        serverSocket.close();
        socket.close();
        inputStream.close();
    }

}
